<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /*arguments参数*/
    function getSum() {
      let sum = 0
      for (let i = 0; i < arguments.length; i++) {
        // arguments参数是函数内部内置的伪数组变量，它包含了调用函数的时候传递进来的所有实参
        sum += arguments[i]
      }
      console.log(arguments);
      return sum
    }
    const res1 = getSum(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    console.log(res1);
    const res2 = getSum(1, 2)
    console.log(res2);

    /*默认参数*/
    function getName(name = "陶品奇") {
      return name
    }
    const res3 = getName()
    console.log(res3);
    const res4 = getName("马云")
    console.log(res4);

    /*剩余参数:应许我们将一个不确定数量的实参表示为一个数组*/
    function getCount(...args) {
      let sum = 0
      for (let i = 0; i < args.length; i++) {
        sum += args[i]
      }
      console.log(args);
      return sum
    }
    const res5 = getCount(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    console.log(res5);
    const res6 = getCount(1, 2)
    console.log(res6);

    function fun(a, b, ...args) {
      console.log(a);//1
      console.log(b);//2
      console.log(args);//[4,5,6,7,8,9,10]
    }
    fun(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
  </script>
</body>

</html>